/**
 * json配置举例，更多配置请看 IConfigSchema
 * @author luguoxiang
 * @date 2022/7/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { FilterTypeEnum, IConfigSchema, LgBizSelect, LgBizSelectProps } from '@/soar';
import userApi, { basePath as userBasePath } from '@/pages/system/auth/user/api';
import { basePath } from './api';
import { MenuComponent } from '@/types/interface';

const fieldList: IConfigSchema<any>[] = [
  {
    field: 'type',
    label: '类型',
    dataType: 'dict',
    params: 'LogTypeEnum',
    table: {
      sorter: true,
      width: 100,
    },
  },
  {
    field: 'userType',
    label: '用户类型',
    dataType: 'dict',
    params: 'user-type',
    table: {
      sorter: true,
      width: 120,
    },
    search: {
      searchType: FilterTypeEnum.CUSTOM,
    },
  },
  {
    field: 'userId',
    label: '用户',
    dataType: 'string',
    table: {
      colKey: 'nickname',
      minWidth: 120,
    },
    search: {
      searchType: FilterTypeEnum.EQ,
      component: LgBizSelect,
      componentProps: {
        data: userApi.query,
        valueField: 'id',
        labelField: '${nickname}(${username})',
        search: 'nickname|username',
      } as LgBizSelectProps,
    },
  },
  {
    field: 'title',
    label: '操作',
    dataType: 'string',
    table: {
      ellipsis: true,
    },
  },
  {
    field: 'content',
    label: '内容',
    dataType: 'string',
    table: {
      ellipsis: true,
    },
  },
  {
    field: 'path',
    label: '接口路径',
    dataType: 'string',
    table: {
      ellipsis: true,
    },
  },
  {
    field: 'startTime',
    label: '操作时间',
    dataType: 'datetime',
    table: {
      width: 150,
    },
  },
  {
    field: 'duration',
    label: '耗时(ms)',
    dataType: 'number',
    table: {
      sorter: true,
      width: 120,
    },
  },
  {
    field: 'clientType',
    label: '终端类型',
    dataType: 'dict',
    params: 'client-type',
    table: {
      sorter: true,
      width: 120,
    },
    search: {
      searchType: FilterTypeEnum.CUSTOM,
    },
  },
  {
    field: 'clientIp',
    label: 'IP',
    dataType: 'string',
    table: {
      width: 135,
    },
  },
  {
    field: 'traceId',
    label: '链路id',
    dataType: 'string',
    table: false,
  },
  {
    field: 'javaMethod',
    label: 'java方法',
    dataType: 'string',
    table: false,
  },
  {
    field: 'userAgent',
    label: '浏览器信息',
    dataType: 'string',
    table: false,
    search: false,
    detail: {
      colProps: {
        style: 'min-width: 100%;',
      },
    },
  },
  {
    field: 'args',
    label: '入参',
    dataType: 'string',
    table: false,
    detail: {
      colProps: {
        style: 'min-width: 100%;',
      },
    },
  },
  {
    field: 'result',
    label: '出参',
    dataType: 'string',
    table: false,
    detail: {
      colProps: {
        style: 'min-width: 100%;',
      },
    },
  },
  {
    field: 'errorStack',
    label: '异常信息',
    dataType: 'string',
    table: false,
    detail: {
      colProps: {
        style: 'min-width: 100%;',
      },
    },
  },
];

export default fieldList;

/**
 * 组件配置（用于生成菜单数据）
 */
export const COMPONENTS: MenuComponent[] = [
  {
    title: '操作日志',
    component: () => import('./List.vue'),
    sort: 10,
    keepalive: true,
    icon: 'view-module',
    permits: [`GET${basePath}/query`, `GET${userBasePath}/query`],
    elements: [
      { title: '删除', code: 'remove', permits: [`POST${basePath}/remove`] },
      { title: '详情', code: 'detail', permits: [`GET${basePath}/detail`] },
    ],
  },
];
